package logik;

import java.sql.SQLException;
import javax.swing.JOptionPane;

/**
 * @author Matthias
 * Represents a deposit ATM transaction
 */
public class Deposit extends Transaction {
	
	private double amount; // amount to deposit
	
	public Deposit (PerformTransactions perform) {
		// initialize superclass variables
		super(perform);	
	} 
	
	@Override
	public void execute() {
		amount = getClassPerform().getClassATM().getClassScreen().getAccDeposit().getInputDepositAmount();
		// check whether user entered a deposit amount or canceled
		if (isEnvelopeReceived()) {
			try {
				// credit account to reflect the deposit
				getClassPerform().getClassATM().getSubBdbAccSQL().creditAccSQL(getAccNr(), amount);
			} catch (SQLException e) {
				JOptionPane.showMessageDialog(null, "No valid envelope received", 
						"Error!", JOptionPane.ERROR_MESSAGE);
			}
		} // end if
		else { 
			JOptionPane.showMessageDialog(null, "No valid envelope received", 
					"Error!", JOptionPane.ERROR_MESSAGE);
		}
	}
	
	/**
	 * @return whether envelope was received.
	 * Always returns true, because this is only a software simulation of a real deposit slot
	 */
	public boolean isEnvelopeReceived() {
		return true;
	}

} // end class Deposit